package com.saicyc.demo.utils;

import lombok.Data;

import javax.persistence.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ynuo
 */
@Data
@MappedSuperclass
public class BaseEntity {

    @Column(name = "created_at")
    @Convert(converter = DateToStringConverter.class)
    private String createdAt;

    @Column(name = "updated_at")
    @Convert(converter = DateToStringConverter.class)
    private String updatedAt;

    @PrePersist
    public void prePersist() {
        this.createdAt = this.updatedAt = new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss").format(new Date());
    }

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss").format(new Date());
    }


}
